
package ch.hearc.meteo.imp.afficheur.real.vue.atome;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;

import org.jfree.data.time.Millisecond;
import org.jfree.data.time.RegularTimePeriod;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;

import ch.hearc.meteo.imp.afficheur.real.moo.StationMeteoElement;
import ch.hearc.meteo.spec.meteo.listener.event.MeteoEvent;

public class JPanelGraphPression extends JPanelGraph
	{

	/*------------------------------------------------------------------*\
	|*							Constructeurs							*|
	\*------------------------------------------------------------------*/

	public JPanelGraphPression(ArrayList<StationMeteoElement> listeStationMeteoElement, String axeX, String axeY)
		{
		super(listeStationMeteoElement, axeX, axeY);
		}

	/*------------------------------------------------------------------*\
	|*							Methodes Public							*|
	\*------------------------------------------------------------------*/

	@Override
	public void refresh()
		{
		TimeSeriesCollection collection = new TimeSeriesCollection();
		synchronized (listeStationMeteoElement)
			{
			for(StationMeteoElement stationMeteoElement:listeStationMeteoElement)
				{
				TimeSeries serie = new TimeSeries(stationMeteoElement.getAffichageOption().getTitre());
				long lastInsertTime = 0;
				List<MeteoEvent> pressionList = stationMeteoElement.getListPression();
				synchronized (pressionList)
					{
					for(MeteoEvent meteoEvent:pressionList)
						{
						if (lastInsertTime != meteoEvent.getTime())
							{
							RegularTimePeriod timePeriod = RegularTimePeriod.createInstance(Millisecond.class, new Date(meteoEvent.getTime()), TimeZone.getDefault());
							serie.add(timePeriod, meteoEvent.getValue());
							}
						lastInsertTime = meteoEvent.getTime();
						}
					}

				collection.addSeries(serie);
				}
			}
		chart.getXYPlot().setDataset(0, collection);
		updateColors();
		repaint();
		}


	/*------------------------------*\
	|*				Set				*|
	\*------------------------------*/

	/*------------------------------*\
	|*				Get				*|
	\*------------------------------*/

	/*------------------------------------------------------------------*\
	|*							Methodes Private						*|
	\*------------------------------------------------------------------*/

	/*------------------------------------------------------------------*\
	|*							Attributs Private						*|
	\*------------------------------------------------------------------*/
	}
